<template>
  <router-view v-slot="{ Component, route }">
    <transition name="fade" mode="out-in" appear>
      <component
          :is="Component"
          v-if="!route.meta.keepAlive"
          :key="route.fullPath"
      />
      <keep-alive v-else :include="cacheList">
        <component :is="Component" :key="route.fullPath" />
      </keep-alive>
    </transition>
  </router-view>
</template>

<script setup lang="ts">
import {onActivated, ref} from "vue";
import {
  // collectModules,
  // collectRouterByObject,
  collectRouterByArray
} from "@/utils/routerCollecter.ts";

// // 获取所有动态路由
// const asyncModules: {
//   [index: string]: {default: any}
// } = import.meta.glob("@/router/asyncModules/*.ts", { eager: true });
// // 整理好模块
// const _modules = collectModules(asyncModules);
// // 整理动态路由
// const asyncRouters = collectRouterByObject(JSON.parse(JSON.stringify(_modules)));

// 获取静态路由
import constantsRouter from "@/router/constants.ts";
// 整理好静态路由
const constants_Router = collectRouterByArray(constantsRouter);
// 需要缓存的页面
const cacheList = ref<Array<string>>([]);
// 所有路由
const allRouters = [...constants_Router];
allRouters.forEach(route => {
  if(route.meta && route.meta.keepAlive) {
    // if(route.re)
    cacheList.value.push(route.name);
  }
})
// console.log(allRouters);
console.log(cacheList.value);

onActivated(() => {
  console.log("被激活了")
})


// import {onMounted} from "vue";
// import HelloWorld from './components/HelloWorld.vue';
//
// import globalConfig from "@/config/globalConfig.ts";
// const { openMobleAdapter } = globalConfig;
//
// let timer: ReturnType<typeof setTimeout> | null = null;
// window.addEventListener('resize', resizeDeal);
// // 当屏幕宽度大于420px时改为手机端iframe
// function resizeDeal() {
//   if (!timer && openMobleAdapter) {
//     const clientWidth = document.body.clientWidth;
//     if(clientWidth >= 420) window.location.href = "/src/assets/html/phone.html";
//     timer = setTimeout(function () {
//       clearTimeout(timer as ReturnType<typeof setTimeout>);
//       timer = null;
//     }, 30);
//   }
// }
// // 页面渲染完成时
// onMounted(() => {
//   resizeDeal();
// })
</script>

<style scoped lang="less">

</style>
